package org.lsp.opencvauto.weixin;

import com.sun.jna.platform.win32.WinUser;
import org.lsp.opencvauto.image.ImageDispose;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.springframework.stereotype.Component;

import java.awt.*;
import java.awt.event.InputEvent;
import java.util.HashMap;
import java.util.Map;

/*
* 识别微信组件
* */
@Component
public class WeixinUI {

    /*
    * 识别微信搜索栏
    * */
    public  Core.MinMaxLocResult  weiXinSearch(){
        Map<String, Object> map = ImageDispose.matchTemplate("matchTemplate/messagerecognition/search1.png", "./weixin.png");
        return  (Core.MinMaxLocResult)map.get("result");
    }
    /*
    * 使用微信搜索栏进行搜索
    * */
    public  void weiXinSearchContext() throws AWTException {
        Core.MinMaxLocResult minMaxLocResult = weiXinSearch();
        Robot robot=new Robot();
        int x=(int)minMaxLocResult.maxLoc.x;
        int y=(int)minMaxLocResult.maxLoc.y;
        robot.mouseMove(x,y);
        robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);

    }

    /**
     * 微信消息窗口的x轴坐标
     * */
    public   Core.MinMaxLocResult   weiXinMessages(){
        Map<String, Object> map = ImageDispose.matchTemplate("matchTemplate/messagerecognition/messages.png", "./weixin.png");
        Mat result=(Mat) map.get("result");

        return Core.minMaxLoc(result);
    }


}
